import request from '@/utils/request'
import {useDecorateApi} from "@/utils/tools";

// 初始化个人中心页面
export function initSelf() {
    return request({
      url: '/bksystem/user/info',
      method: 'get',
    })
}
//上传个人信息
export function uploadSelf(formData) {

  const {promise: setUserPromise} = useDecorateApi(request({
    url: '/bksystem/user',
    method: 'post',
    data: formData
  }), {})

  return new Promise((resolve, reject) => {
    setUserPromise.then((res) => {
      if (!formData.restPassword) {
        resolve(res)
        return
      }
      useDecorateApi(request({
        url: `/bkauth/auth/password?password=${formData.restPassword}&timestamp=${Date.now()}`
      }), {}).promise.then(res => {
        resolve(res)
      }).catch(e => {
        reject(e)
      })
    }).catch(e => {
      reject(e)
    })
  })
}
